class AwardListController {
    constructor($rootScope,$scope,$state,UserService,AccountService,LotteryService){
        Object.assign(this,{$rootScope,$scope,$state,UserService,AccountService,LotteryService});
        this.$rootScope.currentGroup= this.$state.params.cg;
        this.lotTypeList = [{lot_id:-9,"lot_type": "",lot_name:"全部"}, {lot_id:43,"lot_type": "xysc",lot_name:"幸运赛车"},
            {lot_id:46,"lot_type": "cqssc",lot_name:"重庆时时彩"}, {lot_id:49,"lot_type": "gd11x5",lot_name:"广东11选5"}];

        this.queryParam = {
            lotType :this.lotTypeList[0]
        };
        this.orderData = [];
        this.init();
    }

    /**
     * 初始化
     */
    init() {
        let self = this;
        let urlParams = self.$state.params;
        //日期时间范围
        laydate.render({
               elem: '#awardListForm_daterange'
               ,range: '→'
           });

        // self.LotteryService.getLottyTypes().then(_success).catch(_error);
        //
        // function _success(data) {
        //     self.lotTypeList = new Array();
        //     self.lotTypeList.push({lot_id: "-9", lot_type: "-9", lot_name: "全部", lot_logo_img: ""});
        //     data.data_list.forEach(function (item,index,array) {
        //         self.lotTypeList.push(item);
        //     });
        //     self.queryParam.lotType = self.lotTypeList[0];
        //     self.lotTypeList.forEach(function (item, index, array) {
        //         if (urlParams.lot_id && item.lot_id == urlParams.lot_id) {
        //             self.queryParam.lotType = item;
        //         }
        //     })
        //
        //     //执行查询
        //     self.search(1);
        // }
        //
        // function _error(reason) {
        //     console.log(JSON.stringify(reason));
        // }
        //
        // self.statusList.forEach((item, index, array) => {
        //     if (urlParams.status && urlParams.status == item.value) {
        //         self.queryParam.status = item;
        //     }
        // });
            //执行查询
            self.search(1);
    }



    /**
     * 查询
     */
    search(pageNo){
        let self  = this;
        let param = {};
        if(self.queryParam.lotType){
            param.lot_id =  self.queryParam.lotType.lot_id;
        }
        if(self.queryParam.status){
            param.status =  self.queryParam.status.value;
        }else{
            param.status = -9;
        }
        if(pageNo == undefined){
            pageNo = 1;
        }

        //console.log($("#orderListForm_daterange")[0].value);
        let dateRangString = $("#awardListForm_daterange")[0].value;
        if(dateRangString){
            let pieces =   dateRangString.split('→');
            let startDateStr = pieces[0];
            let endDateStr = pieces[1];
            if(startDateStr){
                param.start_date =startDateStr;
            }
            if(endDateStr){
                param.end_date =endDateStr;
            }
        }

        param.daterange =  self.queryParam.daterange1;
        param.page_index=pageNo;
        param.page_size=10;

        //console.log(JSON.stringify(param));
        self.AccountService.getAwardList(param).then(_success).catch(_error);
        function _success(data) {
            // if(data.success==true){
            self.orderData = data.data;
            // }
        }
        function _error(reason) {
            console.log(JSON.stringify(reason));
            // layer.alert(reason&&reason.text?reason.text:"对不起操作失败！",{
            //     title:"错误",
            //     icon: 2,
            //     btn:["知道了"],
            //     btn1:function (index,layerro) {
            //         layer.close(index);
            //     }
            // });
        };
    }
}
AwardListController.$inject = ["$rootScope","$scope","$state","UserService","AccountService","LotteryService"];

export default AwardListController;